// node 43_使用call和this实现继承.js

//组合继承

//父类
function fun1(name) {
    this.name = name
    this.age = 20
}
fun1.prototype.setName=function(name){
    this.name = name
}
fun1.prototype.getName=function(){
    console.log(this.name)
}

//子类
function fun2(name) {  
    fun1.call(this,name)//继承属性     又叫盗用构造函数
}

fun2.prototype = new fun1()//继承方法   单用属于原型链继承

let a = new fun2('张三')
console.log(a.name,a.age)
a.setName('李四')
a.getName()